<style scoped>
.layui-row {
    overflow: hidden;
}

.select-item {
    width: 34.333333%;
    float: right;
}

.layui-row:after,
.layui-row:before {
    clear: none;
}
</style>

<template>
<div class="department">

    <form class="layui-form ">
        <div class="layui-col-lg4 select-item" style="text-align: right;width: auto">
            <div class="layui-inline" style="width: 200px">
                <input type="text" v-model="dailydata" autocomplete="off" name="dailydata" id="dailydata" placeholder="请选择操作日期" class="layui-input key">
            </div>
            <div class="layui-inline" style="width: 200px">
                <select v-model="farmerid" name="farmerid" id="farmerid" lay-filter="farmer" placeholder="请选择种植户" class="layui-form-select">
                    <option value="">请选择种植户</option>
                    <option v-for="item in plantors " :value="item.guid">{{item.realname}}</option>

                </select>
            </div>
            <div class="layui-inline" style="width: 200px">
                <select name="arealandid" id="arealandid" placeholder="请选择地块" class="layui-input layui-unselect">
                    <option value="">请选择地块</option>
                    <option v-for="item in arealands" :value="item.guid">{{item.aName}}</option>
                </select>
            </div>
            <button type="button" class="layui-btn sou" @click="search">搜索</button>
        </div>
    </form>
    <table class="layui-table layui-form">

        <thead>
            <tr>
                <th>订单编号</th>
                <th>地块名称</th>
                <th>种植户名称</th>
                <th>提交人</th>
                <th>提交时间</th>
                <th>最后修改时间</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            <tr class="id9" v-for="(val, index) in opers">
                <td>{{val.ordercode}}</td>
                <td>{{val.landname}}</td>
                <td>{{val.farmername}} </td>
                <td>{{val.operatorname}} </td>
                <td>{{val.creattime}}</td>
                <td>{{val.lastupdtime}}</td>

                <td><a href="javascript:;" @click="toPage(val.guid) ">查看详情</a></td>
            </tr>
        </tbody>
    </table>

    <Pagination :cur="currentPage" :all="totalPage" :callback="turnPage"></Pagination>
</div>
</template>

<script>
import Pagination from '../common/Pagination.vue'
export default {
    name: 'PlantOperation',
    components: {
        Pagination
    },

    data() {
        return {
            arealands: [],
            currentPage: 1,
            totalPage: 0,
            searchName: '',
            opers: [],
            arealandid: "",
            dailydata: "",
            farmerid: "",
            plantors: [],
            obj:{}
        }
    },
    mounted() {

        let that = this;
        layui.use(['form'], function () {
            var form = layui.form,
                layer = layui.layer;
            that.getPageData();
            that.getBaseInfo();
            form.on('select(farmer)', function (data) {
                that.getArealands(data.elem.value);
            });
        });
        layui.use('laydate', function () {
            var laydate = layui.laydate;

            //执行一个laydate实例
            laydate.render({
                elem: '#dailydata' //指定元素
            });

        });

    },
    updated: function () {
        layui.form.render('select');
        layui.form.render();

    },
    methods: {
        search: function () {
            this.getPageData('search');
        },
        turnPage: function (data) {
            this.currentPage = data;
            this.getPageData();
        },
        getPageData: function (type = '') {
            let that = this;
            let loader = layui.layer.load();

            let postData = {
                pageSize: 10
            };
            if (type != 'search') {
                postData.pageNo = that.currentPage;
            }else{
                postData.pageNo = 1;
            }

            that.farmerid = $('#farmerid').val();
            that.arealandid = $('#arealandid').val();
            that.dailydata = $('#dailydata').val();

            postData.huserid = sessionStorage.getItem('userid');
            postData.farmerid = that.farmerid;
            postData.arealandid = that.arealandid;
            if (that.dailydata != "") {
                postData.creattime = that.dailydata;
            }
            postData.functiontype = 25;
            $.ajax({
                url: '/farmer/Plantoperation!list.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    if (res.status == 'success') {
                        //分页数据赋值
                        that.currentPage = res.result.pageNo;
                        that.totalPage = res.result.pageCount;
                        that.opers = res.result.rows;
                    } else {
                        that.alert("系统错误");
                    }
                },
                complete: function () {
                    layer.close(loader);
                }
            });
        },
        toPage: function (id) {
            let that = this;
            this.$parent.gid = id;
            this.$parent.switchPage('ExportPlantOperation');
        },
        getBaseInfo: function (type = '') {
            var that = this;
            let postData = {
            };
            $.ajax({
                url: '/harvest/Procurementcontract!getPlanters.action',
                type: "post",
                data: postData,
                dataType: "json",
                success: function (res) {
                    if (res.msg == 'success') {
                        that.plantors = res.planters;
                    } else {
                        that.toast('获取种植户数据失败！');
                    }
                }
            });
        },
        getArealands: function(plantorid) {
            let that = this;
            this.axios({
                method: 'get',
                url: '/harvest/Procurementcontract!getArealand.action',
                params: {userid: plantorid}
            }).then(response => {
                if (response.data.msg == 'success') {
                    that.arealands = response.data.arealands;
                    layui.form.render('select');
                } else {
                    this.toastText('获取地块数据失败')
                }
            });
        },
    }
}
</script>
